package com.aaa.sbm.controller;

import com.aaa.sbm.entity.Order;
import com.aaa.sbm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 封装从ES中查询的方法
     * @param type
     * @param propertyName
     * @param value
     * @return
     */
    @RequestMapping("queryInEs")
    public List<Order> queryInEs(@RequestParam(required = false,defaultValue = "1") Integer type, String propertyName, String value){
        return orderService.queryInEs(type,propertyName,value);
    }

    /**
     * 向ES中添加或者更新数据
     * @param order
     * @return
     */
    @RequestMapping("addOrUpdate")
    public int addOrUpdate(Order order){
        return orderService.addOrUpdate(order);
    }

    /**
     * 根据ID删除文档
     * @param id
     * @return
     */
    @RequestMapping("deleteById")
    public int deleteById(Long id){
        return orderService.deleteById(id);
    }
}
